import logging
import sys
from config import get_config

config = get_config()

# 配置日志格式
log_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'

def setup_logger(name):
    """设置日志记录器"""
    logger = logging.getLogger(name)
    
    # 如果已经设置过处理器，直接返回
    if logger.handlers:
        return logger
    
    # 设置日志级别
    logger.setLevel(getattr(logging, config.LOG_LEVEL))
    
    # 创建控制台处理器
    console_handler = logging.StreamHandler(sys.stdout)
    console_handler.setLevel(getattr(logging, config.LOG_LEVEL))
    
    # 创建格式化器
    formatter = logging.Formatter(log_format)
    console_handler.setFormatter(formatter)
    
    # 添加处理器到记录器
    logger.addHandler(console_handler)
    
    return logger